﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            var a = 1.5;
            var source = new List<double>();
            for (int i = 0; i < 58; i++)
            {
                source.Add(a);
            }

            Assert.AreEqual(GetScore(source, 50), 50 * a);
            Assert.AreEqual(GetScore(source, 101), 101 * a);
            Assert.AreEqual(GetScore(source, 251), 251 * a);
            Assert.AreEqual(GetScore(source, 99), 99 * a);
            Assert.AreEqual(GetScore(source, 1000011111), 1000011111 * a);
            Assert.AreEqual(GetScore(source, 10), 10 * a);
            Assert.AreEqual(GetScore(source, 199), 199 * a);

            List<double> s = JsonConvert.DeserializeObject<List<double>>("[11.0,16.0,16.0,17.0,18.0,14.0,11.0,12.0,16.0,17.0,15.0,17.0,14.0,18.0,13.0,19.0,18.0,16.0,18.0,18.0,14.0,18.0,13.0,11.0,19.0,14.0,19.0,14.0,13.0,17.0]");

            Assert.AreEqual(GetScore(s, 56), 869);
        }

        private double GetScore(List<double> source, int clicknum)
        {
            var result = (double)0;
            int count = source.Count;
            if (clicknum > count)
            {
                var num = clicknum / count;
                result += source.Sum() * num;
                clicknum = clicknum % count;
            }
            for (int i = 0; i < clicknum; i++)
            {
                result += source[i];
            }
            return result;
        }
    }
}
